package com.ljy.controller.admin;

import com.ljy.dto.EmpLoginDTO;
import com.ljy.result.Result;
import com.ljy.service.EmpService;
import com.ljy.vo.EmpLoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/employee")
public class EmpController {
    @Autowired
    EmpService empService;
    @PostMapping("/login")
    public Result<EmpLoginVO> login(EmpLoginDTO dto){
        String jwt = empService.login(dto);
        if(jwt==null){
            throw new RuntimeException("账号密码错误");
        }
        EmpLoginVO empLoginVO=new EmpLoginVO();
        empLoginVO.setUsername(dto.getUsername());
        empLoginVO.setToken(jwt);
        return Result.success(empLoginVO);
    }


}
